package bombermanGame;

import org.newdawn.slick.AngelCodeFont;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.MouseOverArea;
import org.newdawn.slick.gui.TextField;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class LoginMenuState extends BasicGameState implements ComponentListener {
	
	public static int ID = 3;
	/** the game holding this state*/
	private StateBasedGame game;
	/** the container of the game */
	private GameContainer container;
	private Image background;
	private Image logo;
	private Image bombermanLogo;
	private Image loginButton;
	private Image backButton;
	private Image usernameLabel;
	private Image passwordLabel;
	private TextField userName;
	private TextField password;
	private Font font;
	
	private MouseOverArea loginButtonMouseOverArea;
	private MouseOverArea backButtonMouseOverArea;

	@Override
	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		this.game = game;
		this.container = container;
		
		background = new Image("/images/GameMenuImages/background.jpg");
		logo = new Image("/images/GameMenuImages/logo.png");	
		bombermanLogo = new Image("images/GameMenuImages/bombermanLogo.gif");
		
		backButton = new Image("images/GameMenuImages/backButton.png");
		loginButton = new Image("images/GameMenuImages/loginButton.png");
		
		font = new AngelCodeFont("images/GameMenuImages/demo2.fnt","images/GameMenuImages/demo2_00.tga");
		usernameLabel = new Image("/images/GameMenuImages/usernameLabel.png");
		passwordLabel = new Image("/images/GameMenuImages/passwordLabel.png");
		userName = new TextField(container, font, 400, 250, 200, 30, this);
		password = new TextField(container, font, 400, 310, 200, 30, this);
		
		// login button area
		loginButtonMouseOverArea = new MouseOverArea(container, loginButton, 400, 370, loginButton.getWidth(), loginButton.getHeight(), this);
		loginButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		loginButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// register button area
		backButtonMouseOverArea = new MouseOverArea(container, backButton, 400, 420, backButton.getWidth(), backButton.getHeight(), this);
		backButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		backButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		background.draw(0, 0);
		logo.draw(70, 100);
		bombermanLogo.draw(140, 220);
		
		usernameLabel.draw(280, 260);
		passwordLabel.draw(280, 315);
		
		backButtonMouseOverArea.render(container, g);
		loginButtonMouseOverArea.render(container, g);
		userName.render(container, g);
		password.render(container, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		
	}

	@Override
	public int getID() {
		return ID;
	}

	@Override
	public void componentActivated(AbstractComponent source) {
		if(source == backButtonMouseOverArea) {
			game.enterState(MainMenuState.ID);
		}
	}

}
